﻿using System.Collections.Generic;
using System.Linq;

using ManageSystemServer.DAO;
using ManageSystemServer.Entity;
namespace ManageSystemServer.Service
{
    public class AdminService : IService
    {
        public string ServiceName => nameof(AdminService);

        //依赖注入
        private readonly ServerContext context;

        public AdminService(ServerContext context)
        {
            this.context = context;
        }

        //查询
        public List<Admin> GetAllAdmins()
        {
            return context.Admins.Where(m => true).ToList();
        }
        //添加
        public bool AddAdmin(uint AdminId, string Password)
        {
            var res = context.Admins.Where(m => m.AdminId.Equals(AdminId)).FirstOrDefault();
            if (res != null)
            {
                return false;
            }
            else
            {
                context.Admins.Add(new Admin { AdminId = AdminId, Password = Password });
                context.SaveChanges();
            }
            return true;
        }

        //验证
        public bool Authentize(uint AdminId, string Password)
        {
            var res = context.Admins.Where(m => m.AdminId.Equals(AdminId) && m.Password.Equals(Password)).FirstOrDefault();
            return res != null;
        }

    }
}
